package com.yoda.youdianda.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 11月 14日 9:22
 * 分页查询返回数据模板
 */
@Data
@AllArgsConstructor
public class PageResult<T> {
    private Integer count;
    private Integer totalPages;
    private Integer currentPage;
    private Integer pageSize;
    private List<T> data;

    public PageResult(Integer currentPage, Integer pageSize, Integer count, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        if (Objects.isNull(count)){
            this.count = 0;
        }else{
            this.count = count;
        }
        this.data = data;
        this.totalPages = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;//计算总页数
    }

    public PageResult() {
        count=0;
        totalPages=0;
        currentPage=0;
        pageSize=0;
        data = new ArrayList<>();
    }
}
